<!--
 描述: 双轴柱状图
 作者: Jack Chen
 日期: 2020-04-27
-->

<template>
  <div class="hbh-container">
    <commonTitle :title="'楼栋设备耗能排名'" />
    <div class="bothBox">
      <div class="someone">
        <div class="tipBox">
          耗水/吨
        </div>
        <div class="itemBox" v-for="(item, index) in data" :key="index">
          <div class="title">
            {{ item.name }}
          </div>
          <div class="process">
            <span></span
            ><span :style="{ width: (item.value / total) * 100 + '%',background: 'linear-gradient(to right, #39865D, #60E29C)' }"></span>
            <div
              class="showValue"
              :style="{ left: (item.value / total) * 100 + '%' }"
            >
              {{ item.value }}
            </div>
          </div>
        </div>
      </div>
      <div class="someone">
        <div class="tipBox">
          耗电/万度
        </div>
        <div class="itemBox" v-for="(item, index) in data2" :key="index">
          <div class="title">
            {{ item.name }}
          </div>
          <div class="process">
            <span></span
            ><span :style="{ width: (item.value / total2) * 100 + '%',background: 'linear-gradient(to right, #3B67D8, #6591FE)' }"></span>
            <div
              class="showValue"
              :style="{ left: (item.value / total2) * 100 + '%' }"
            >
              {{ item.value }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "szBar",
  data() {
    return {
      data: [
        {
          name: "A1",
          value: 107,
        },
        {
          name: "A2",
          value: 67,
        },
        {
          name: "B2",
          value: 23,
        },
        {
          name: "B3",
          value: 55,
        },
        {
          name: "A3",
          value: 78,
        },
        {
          name: "A4",
          value: 88,
        },
        {
          name: "B4",
          value: 98,
        },
        {
          name: "A5",
          value: 148,
        },
      ],
      total: 200, //总数量
      data2: [
        {
          name: "A6",
          value: 127,
        },
        {
          name: "B6",
          value: 67,
        },
        {
          name: "A7",
          value: 13,
        },
        {
          name: "A8",
          value: 73,
        },
        {
          name: "B7",
          value: 78,
        },
        {
          name: "B8",
          value: 76,
        },
        {
          name: "A9",
          value: 98,
        },
        {
          name: "A10",
          value: 108,
        },
      ],
      total2: 200, //总数量
    };
  },
  mounted() {},
  methods: {},
  beforeDestroy() {},
};
</script>

<style lang="scss" scoped>
.hbh-container {
  width: 100%;
  margin-bottom: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .bothBox {
    width: 100%;
    display: flex;
    align-items: center;
    .someone {
      width: 50%;
      display: flex;
      flex-direction: column;
      align-items: center;
      position: relative;
      padding-top: 40px;
      .tipBox{
        position: absolute;
        width: 100px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        background-image:url("https://files.axshare.com/gsc/E0EL5C/fd/21/59/fd2159f2f7f94050a3ed7c0fb1c4079a/images/%E7%83%AD%E6%B3%B5%E7%B3%BB%E7%BB%9F/u104.svg?pageId=1faa738d-2fb6-4c2f-b893-e9f972d8c348");
        background-repeat: no-repeat;
        background-size:100% 100%;
        top: 10px;
        left:calc(50% - 50px);
      }
      .itemBox {
        width: 100%;
        display: flex;
        align-items: center;
        .title {
          width: 40px;
          height: 40px;
          line-height: 40px;
          padding-left: 10px;
          box-sizing: border-box;
        }

        .process {
          width: calc(100% - 70px);
          height: 40px;
          display: flex;
          align-items: center;
          position: relative;
          .showValue {
            position: absolute;
            height: 40px;
            line-height: 40px;
            left: 80%;
            top: calc(50% - 20px);
          }
          span {
            position: absolute;
            width: 100%;
            height: 8px;
            background-color: #435b6e;
            border-top-right-radius: 5px;
            border-bottom-right-radius: 5px;
          }
          span:nth-of-type(2) {
            width: 80%;
            position: relative;
            background: linear-gradient(to right, #435b6e, #81d3f8);
            border-top-right-radius: 5px;
            border-bottom-right-radius: 5px;
          }
        }
      }
    }
  }
}
</style>
